import type {
  ArticleList,
  ArticleParams,
  ChannelList,
  FormRes,
  FormType,
  PublishArticleParams,
  UserData,
} from '@/types'
import { request } from '@/utils/http'

// 登录
export const loginAPI = (value: FormType) => {
  return request<FormRes>('/v1_0/authorizations', 'POST', value)
}

// 获取用户资料
export const getUserDataAPI = () => {
  return request<UserData>('/v1_0/user/profile', 'GET')
}

// 获取频道列表
export const getChannelListAPI = () => {
  return request<ChannelList>('/v1_0/channels', 'GET')
}

// 获取文章列表信息
export const getArticleListAPI = (value: ArticleParams) => {
  return request<ArticleList>('/v1_0/mp/articles', 'GET', value)
}

// 删除文章
export const delArticleAPI = (id: string, params: { draft: boolean }) => {
  return request<ArticleList>(`/v1_0/mp/articles/${id}`, 'DELETE', params)
}

// 上传图片
export const uploadAPI = (fd: FormData) => {
  return request<{ url: string }>('/v1_0/upload', 'POST', fd)
}

// 发表文章
export const publishArticleAPI = (params: PublishArticleParams, draft: boolean) => {
  return request<ArticleList>(`/v1_0/mp/articles?draft=${draft}`, 'POST', params)
}
// 获取文章详情 /v1_0/mp/articles/:target
export const getArticleDetailAPI = (id: string) => {
  return request<PublishArticleParams>(`/v1_0/mp/articles/${id}`, 'GET')
}
